<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * Framework_Quickform
 *
 * @author      Ian Szewczyk <roamzero@gmail.com>
 * @copyright   (c) 2007 Ian Szewczyk. All rights reserved.
 * @license     http://www.opensource.org/licenses/bsd-license.php
 * @package Framework
 * @filesource
 */

require_once "HTML/QuickForm.php";

/**
 * Framework_Quickform
 *
 * This class can be used to create an instance of a PEAR Quickform object.
 * It also provides some reusable filters and rules.
 *
 * @author Ian Szewczyk <roamzero@gmail.com>
 * @package Framework
 */
abstract class Framework_QuickForm
{
    /**
     * factory
     *
     * @access 		public	
     * @param		string		$formName
     * @param		string		$method
     * @param		string		$action
     * @param		string		$target
     * @param 		array		$attributes
     * @param 		boolean		$trackSubmit
     * @return 		mixed 		Instance of HTML_Quickform on success, PEAR_Error
     * @static
     */
    static public function factory($formName = '', $method = 'post', $action = '', $target = '', $attributes = null, $trackSubmit = false)
    {
        return new HTML_Quickform($formName, $method, $action, $target, $attributes, $trackSubmit);
    }
    
    /**
     * captchaFiglet
     *
     * @access 		public	
     * @param		HTML_Quickform		$form
     * @param		string				$question
     * @param		string				$label
     * @return 		array
     * @static
     */
    static public function captchaFiglet($form, $question = 'What does this say?', $label = 'Enter Answer') 
    {
    	require_once 'HTML/QuickForm/CAPTCHA/Figlet.php';
    	$options = array('sessionVar' => Framework::$request->module.Framework::$request->event,
                         'options'    => array('font_file' => array(
		                     FRAMEWORK_BASE_PATH.'/Framework/Quickform/CaptchaFiles/Figlet/basic.flf',
		                     FRAMEWORK_BASE_PATH.'/Framework/Quickform/CaptchaFiles/Figlet/big.flf',
		                     FRAMEWORK_BASE_PATH.'/Framework/Quickform/CaptchaFiles/Figlet/nancyj.flf')));
    	
    	$result = array();
    	$result['question'] = $form->addElement('CAPTCHA_Figlet', 'captcha_question', $question, $options);
    	if (PEAR::isError($result['question'])) {
    		return $result['question'];
    	}
    	$result['input'] = $form->addElement('text', 'captcha_input', $label);
    	
    	$form->addRule('captcha_input', 'Enter the letters you see', 'required');
    	
    	$form->addRule('captcha_input', 'What you entered didn\'t match the letters', 'CAPTCHA', $result['question']);

        return $result;
    	
    }
}

?>
